<?php
class ecHelper{

  private static $helperDir;
  private static $listHelper = array();
 
  static public function setHelperDir()
  {
    self::$helperDir = str_replace(DIRECTORY_SEPARATOR, '/', realpath(dirname(__FILE__).DIRECTORY_SEPARATOR));
  }
  
  static public function getHelperDir()
  {
    return self::$helperDir;
  }

  static public function setListHelper()
  {
    self::setHelperDir();

    $dir = opendir(self::getHelperDir());

    $files= array();

    while($file = readdir($dir))
      {
        if($file != '.' && $file != '..')
        {
          if (!is_dir(self::getHelperDir().'/'.$file))
          {
            $nameController = basename($file, false === strpos($file, '.helper.php') ? '.php' : '.helper.php');

            $files[$nameController] = self::getHelperDir().'/'.$file;
          }
        }
      }

    self::$listHelper = $files;
  }

  static public function getListHelper()
  {
    return self::$listHelper;
  }

  static public function loadHelper($nameHelper)
  {
    $helpers = ecAppConfiguration::getHelpers();
    require($helpers[$nameHelper]);
  }

}
